package com.example.myapplication;

import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
import com.example.myapplication.adapters.RecyclerAdapter;
import com.example.myapplication.tools.DataTool;

public class RecyclerActivity extends AppCompatActivity {

    private String TAG = "sun";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main3);

        RecyclerView recyclerView = findViewById(R.id.recycler_view);

        //线性排布，与ListView效果一样
//        recyclerView.setLayoutManager(new LinearLayoutManager(this));

        //网格排布，出来像table
//        recyclerView.setLayoutManager(new GridLayoutManager(this, 3));

        //瀑布流排布
        recyclerView.setLayoutManager(new StaggeredGridLayoutManager(3, 1));

        RecyclerAdapter recyclerAdapter = new RecyclerAdapter(DataTool.getUserInfo(20), this);

        recyclerAdapter.setRecyclerItemClickListener(new RecyclerAdapter.OnRecyclerItemClickListener() {
            @Override
            public void OnRecyclerItemClick(int position) {
                Toast.makeText(RecyclerActivity.this, "点了第" + position + "个", Toast.LENGTH_SHORT);
                Log.d(TAG, "OnRecyclerItemClick: " + position);
            }
        });

        recyclerView.setAdapter(recyclerAdapter);


    }
}